package com.atguigu.lease.web.api.controller;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.CityInfo;
import com.atguigu.lease.model.entity.DistrictInfo;
import com.atguigu.lease.model.entity.ProvinceInfo;
import com.atguigu.lease.web.api.service.CityInfoService;
import com.atguigu.lease.web.api.service.DistrictInfoService;
import com.atguigu.lease.web.api.service.ProvinceInfoService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/app/region")
@Tag(name = "首页区域信息模块")
public class RegionController {
    @Resource
    ProvinceInfoService provinceInfoService;
    @Resource
    CityInfoService cityInfoService;
    @Resource
    DistrictInfoService districtInfoService;
    @Operation(summary = "查询省列表")
    @GetMapping("/province/list")
    public Result<List<ProvinceInfo>> list(){
        return Result.ok(provinceInfoService.list());
    }
    ///city/listByProvinceId?id=44
    @Operation(summary = "查询市列表")
    @GetMapping("city/listByProvinceId")
    public Result<List<CityInfo>> listCityInfos(@RequestParam("id")Long provinceId){
        return Result.ok(cityInfoService.list(Wrappers.lambdaQuery(CityInfo.class)
                .eq(CityInfo::getProvinceId , provinceId)));
    }
    ///district/listByCityId?id=4403
    @Operation(summary = "查询区列表")
    @GetMapping("district/listByCityId")
    public Result<List<DistrictInfo>> listDistrictInfos(@RequestParam("id")Long cityId){
        return Result.ok(districtInfoService.list(Wrappers.lambdaQuery(DistrictInfo.class)
                .eq(DistrictInfo::getCityId , cityId)));
    }
}
